package com.bruce.starts.demo.poi.service;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelStyleType;
import com.bruce.starts.demo.poi.dto.ProdGrayClothVatReportDTO;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class EasyPotExportDemo2 {
    public static void main(String[] args) throws IOException {
        export();
//        Collection<Integer> intCollection = Lists.newArrayList(1, 2, 3);
//
//        Iterable<List<Integer>> subSets = Iterables.partition(intCollection, 10);
//        subSets.forEach(list-> System.out.println(Arrays.toString(list.toArray())));
    }
    public static void export() throws IOException {
        // 获取模板
        TemplateExportParams params = new TemplateExportParams(
                "D:\\04_资源\\\\clothExportOrderTemplate.xlsx");
        params.setHeadingRows(2);
        params.setHeadingStartRow(2);
        params.setStyle(ExcelStyleType.BORDER.getClazz());
        Map<String, Object> map = buildData();
        Map<Integer, List<Map<String, Object>>> realMap = new HashMap<>();
        realMap.put(0, Stream.of(map).collect(Collectors.toList()));
        realMap.put(1, Stream.of(map).collect(Collectors.toList()));
        //realMap.put(2,list);
        Workbook workbook = ExcelExportUtil.exportExcelClone(realMap,params);
        File savefile = new File("D:\\04_资源\\test.xlsx");
        if (!savefile.exists()) {
            savefile.mkdir();
        }
        FileOutputStream fos = new FileOutputStream(savefile);
        workbook.write(fos);
    }

    public static Map<String,Object> buildData(){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("factory","测试工厂");
        map.put("address","广州");
        map.put("exportOrderNo","export0001");
        map.put("parentOrderId","etetete");
        map.put("parentOrderId","customerName");
        map.put("orderNo","wtwetewtwet");
        map.put("outDate", DateTimeFormatter.ofPattern("yyyy-MM-hh").format(LocalDateTime.now()));
        map.put("color","red");
        map.put("varietyName","品种2");
        map.put("varietyNum","品种编号2222");
        map.put("productNum","productNum123123");
        map.put("batchNum","批号0-01");
        map.put("grade","AA");
        map.put("vatNum","DDDDDD");
        map.put("remark","备注12222");
        map.put("totalRoll",2);
        map.put("totalMeter",20000);
        map.put("date", DateTimeFormatter.ofPattern("yyyy-MM-hh").format(LocalDateTime.now()));
        List<Map<String,Object>> inventoryList = new ArrayList<>();
        for(int i=0;i<2;i++){
            Map<String,Object> m1 = new HashMap<>();
            m1.put("seq",(i+1)+"");
            m1.put("one",1);
            m1.put("two",2);
            m1.put("three",3);
            m1.put("four",4);
            m1.put("five",5);
            m1.put("six",6);
            m1.put("seven",7);
            m1.put("eight",8);
            m1.put("nine",9);
            m1.put("ten",10);
            inventoryList.add(m1);
        }
        map.put("map",inventoryList);
        return map;
    }
}
